package com.ruoyi.ybUpload.service.upload.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.ybUpload.domain.MainForm;
import com.ruoyi.ybUpload.domain.QueryParams;
import com.alibaba.fastjson.JSON;
import com.ruoyi.ybUpload.domain.tableCode.BusinessRecords;
import com.ruoyi.ybUpload.service.upload.YBUploadBusinessService;
import com.ruoyi.ybUpload.service.upload.YBUploadService;
import com.ruoyi.ybUpload.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class YBUploadServiceImpl implements YBUploadService {

    @Autowired
    private YBUploadBusinessService ybUploadBusinessService;

    @Override
    public String uploadData(QueryParams queryParams) {
        //todo:策略模式，组装input
        if("stocktaking".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadStocktaking(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("entryStock".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadEntryStock(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("outStock".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadOutStock(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("uploadSell".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadSell(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("consumables".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadConsumables(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("select3501".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadSelect3501(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("select3502".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadSelect3502(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("select3503".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadSelect3503(queryParams);
            return "mainForm";

        }
        if("select3505".equals(queryParams.getBusinessType())){
            List<MainForm> list = ybUploadBusinessService.uploadSelect3505(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }
        if("select3504".equals(queryParams.getBusinessType())) {
            List<MainForm> list = ybUploadBusinessService.uploadSelect3504(queryParams);
            uploadData(list, queryParams);
            return "mainForm";
        }

        //判断登录接口signin
        if("signin".equals(queryParams.getBusinessType())){
            String mainForm = ybUploadBusinessService.uploadSignIn(queryParams);
            return mainForm;
        }

        return null;
    }

    public void uploadData(List<MainForm> list,  QueryParams queryParams){
        System.out.println("调用接口数："+list.size());
        for (MainForm e:list) {
            if("test".equals(queryParams.getType())){
                System.out.println(JSON.toJSONString(e));
            }
            if("prod".equals(queryParams.getType())){
                CommonUtils commonUtils = new CommonUtils();
                System.out.println(JSON.toJSONString(e));
                String s = commonUtils.connect(JSON.toJSONString(e));
                System.out.println("result："+s);
            }
        }
    }

    public void insertRecord(MainForm e, QueryParams queryParams){
//        String json = JSON.toJSONString(e);
//        ObjectMapper mapper = new ObjectMapper();
//        JsonNode jsonNode = mapper.readTree(json);
//        jsonNode.get("")

        BusinessRecords business = new BusinessRecords();
        business.setBusiness_type(queryParams.getBusinessType());
        //business.setGoods_type(e.getInput().get());
    }





}
